# $Id: PKGBUILD 84536 2013-02-19 15:03:09Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Sebastian Faltoni <sebastian.faltoni@gmail.com>

pkgname=dbmail
pkgver=3.0.2
pkgrel=9
pkgdesc="Fast and scalable sql based mail services"
arch=('i686' 'x86_64')
depends=('gmime24' 'libzdb' 'mhash' 'libevent')
makedepends=('asciidoc' 'xmlto' 'docbook-xsl' 'docbook-xml' 'postgresql-libs>=8.4.1'
	     'sqlite' 'libmysqlclient' 'libldap>=2.4.18' 'libsieve')
optdepends=('libldap: for LDAP authentication'
	    'libsieve: for dbmail-sieve')
url="http://www.dbmail.org"
license=('GPL')
options=('!libtool' 'zipman')
backup=(etc/conf.d/dbmail
	etc/xinetd.d/dbmail-imapd
	etc/xinetd.d/dbmail-pop3d
	etc/xinetd.d/dbmail-lmtpd
	etc/xinetd.d/dbmail-timsieved)
source=(http://www.dbmail.org/download/3.0/dbmail-${pkgver/_/-}.tar.gz
	dbmail.conf.d
	dbmail.rc.d
	dbmail.tmpfiles
	dbmail-imapd.service
	dbmail-lmtpd.service
	dbmail-pop3d.service
	dbmail-timsieved.service
	dbmail-imapd.xinetd
	dbmail-lmtpd.xinetd
	dbmail-pop3d.xinetd
	dbmail-timsieved.xinetd)
md5sums=('eb32235abffdf967253ee9d004e0e4a9'
         'e7f72bc360decdb2475266391ad12329'
         '30774513fb016b9da08e9cf6f2a0b8e7'
         'c4b5793c5422b62a675d4c66ff7e9300'
         '84efa46eaac66057c4eb131d9bc27fa8'
         '19560277f6a56d1f3f2fdb02315dcf0f'
         '89a0f793737eaf36291409f8c840891e'
         'dd1b5b2c542f55d9d934a58a36d0513d'
         '8fa791f2e4d107ba461453c054359477'
         '069cd4285c4b2ec95dfdcebc2cfee387'
         '44f87ce81e786fcee501daa17e55412a'
         'a66927cb94d4f26428211e3ad2d540c8')

build() {
  cd $srcdir/dbmail-${pkgver/_/-}/

  [ -f Makefile ] || ./configure --prefix=/usr --with-ldap --with-sieve
  make
}

package() {
  cd $srcdir/dbmail-${pkgver/_/-}/
  make DESTDIR=$pkgdir install
  (cd man && make && make install DESTDIR=$pkgdir)

  mkdir $pkgdir/etc
  install -Dm644 dbmail.conf $pkgdir/etc/dbmail.conf.sample
  install -Dm644 ../dbmail.conf.d $pkgdir/etc/conf.d/dbmail
  install -Dm755 ../dbmail.rc.d $pkgdir/etc/rc.d/dbmail
  mkdir $pkgdir/usr/share/dbmail
  cp -r sql/* $pkgdir/usr/share/dbmail/
  cp dbmail.schema $pkgdir/usr/share/dbmail/

  for i in dbmail-imapd dbmail-lmtpd dbmail-pop3d dbmail-timsieved; do
    install -Dm0644 $srcdir/$i.service $pkgdir/usr/lib/systemd/system/$i.service
    install -Dm0644 $srcdir/$i.xinetd $pkgdir/etc/xinetd.d/$i
  done

  install -Dm0644 $srcdir/dbmail.tmpfiles $pkgdir/usr/lib/tmpfiles.d/dbmail.conf
}
